from tortoise import BaseDBAsyncClient


async def upgrade(db: BaseDBAsyncClient) -> str:
    return """
        CREATE TABLE IF NOT EXISTS `ai_conversations` (
    `id` INT NOT NULL PRIMARY KEY AUTO_INCREMENT COMMENT '主键ID',
    `question` LONGTEXT NOT NULL COMMENT '用户问题',
    `answer` LONGTEXT NOT NULL COMMENT 'AI回答',
    `created_at` DATETIME(6) NOT NULL COMMENT '创建时间' DEFAULT CURRENT_TIMESTAMP(6),
    `user_id` INT COMMENT '用户ID（可选）',
    CONSTRAINT `fk_ai_conve_user_9445609c` FOREIGN KEY (`user_id`) REFERENCES `user` (`user_id`) ON DELETE CASCADE
) CHARACTER SET utf8mb4 COMMENT='AI问答记录表';"""


async def downgrade(db: BaseDBAsyncClient) -> str:
    return """
        DROP TABLE IF EXISTS `ai_conversations`;"""
